package com.song.study.springclouddemo.controller;

import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.atomic.AtomicInteger;

@RestController
@RequestMapping(value = "/order")
@EnableDiscoveryClient
public class OrderApi {

    private static final AtomicInteger atomicInteger = new AtomicInteger(1);

    @GetMapping(value = "/get/{params}")
    public Object getOrder(@PathVariable("params") String params){
        OrderInfo orderInfo = new OrderInfo();
        orderInfo.setOrderId(System.currentTimeMillis()+"");
        orderInfo.setOrderName("orderName:" + params + " " + atomicInteger.addAndGet(1));
        return orderInfo;
    }

    static class OrderInfo{
        private String orderId;

        private String orderName;

        public String getOrderId() {
            return orderId;
        }

        public void setOrderId(String orderId) {
            this.orderId = orderId;
        }

        public String getOrderName() {
            return orderName;
        }

        public void setOrderName(String orderName) {
            this.orderName = orderName;
        }
    }
}
